﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace NNLInterface
{
    public partial class frmBaseToolXC : NNLInterface.frmBaseXC
    {

        //定义按钮事件
        public delegate void ButtonClickEventHandler(object sender, string e);
        public event ButtonClickEventHandler ToolButtonClick;

        private DevExpress.XtraBars.BarManager _barmanager;
        public DevExpress.XtraBars.BarManager barmanager
        {
            get
            {
                return this.barManager;
            }
            set
            {
                if (this.barManager == value)
                    return;
                this.barManager = value;
            }
        }

        
        public DevExpress.XtraBars.BarSubItem BarStyle
        {
            get
            {
                return barStyle;
            }
            set
            {
                if (barStyle == value)
                    return;
                barStyle = value;
            }
        }

        #region 按钮可视及有效性设定

        //各按钮的可视性
        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定新增按钮的可视化")]
        public bool NewButtonVisibility
        {
            get { return this.cmdNew.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdNew.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }

        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定取消按钮的可视化")]
        public bool CancelButtonVisibility
        {
            get { return this.cmdCancel.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdCancel.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }

        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定保存按钮的可视化")]
        public bool SaveButtonVisibility
        {
            get { return this.cmdSave.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdSave.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }


        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定退出按钮的可视化")]
        public bool ExitButtonVisibility
        {
            get { return this.cmdExit.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdExit.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }


        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定导入按钮的可视化")]
        public bool ImportButtonVisibility
        {
            get { return this.cmdImport.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdImport.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }

        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定导出excel按钮的可视化")]
        public bool ExcelButtonVisibility
        {
            get { return this.cmdExcel.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdExcel.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }

        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定打印按钮的可视化")]
        public bool PrintButtonVisibility
        {
            get { return this.cmdPrint.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdPrint.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }


        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定查找按钮的可视化")]
        public bool SearchButtonVisibility
        {
            get { return this.cmdSearch.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdSearch.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }

        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定履历按钮的可视化")]
        public bool logButtonVisibility
        {
            get { return this.cmdLog.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdLog.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }


        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定修改按钮的可视化")]
        public bool EditButtonVisibility
        {
            get { return this.cmdEdit.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdEdit.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }

        [Bindable(true), Category("工具栏按钮可视化设定"), Description("设定删除按钮的可视化")]
        public bool DeleteButtonVisibility
        {
            get { return this.cmdDelete.Visibility == DevExpress.XtraBars.BarItemVisibility.Always ? true : false; }
            set { this.cmdDelete.Visibility = (value == true ? DevExpress.XtraBars.BarItemVisibility.Always : DevExpress.XtraBars.BarItemVisibility.Never); }
        }


     

        //各按钮的有效性
        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定修改按钮的有效性")]
        public bool EditButtonEnabled
        {
            get { return this.cmdEdit.Enabled; }
            set { this.cmdEdit.Enabled = value; }
        }

        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定删除按钮的有效性")]
        public bool DeleteButtonEnabled
        {
            get { return this.cmdDelete.Enabled; }
            set { this.cmdDelete.Enabled = value; }
        }


        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定新增按钮的有效性")]
        public bool NewButtonEnabled
        {
            get { return this.cmdNew.Enabled; }
            set { this.cmdNew.Enabled = value; }
        }

        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定取消按钮的有效性")]
        public bool CancelButtonEnabled
        {
            get { return this.cmdCancel.Enabled; }
            set { this.cmdCancel.Enabled = value; }
        }

        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定保存按钮的有效性")]
        public bool SaveButtonEnabled
        {
            get { return this.cmdSave.Enabled; }
            set { this.cmdSave.Enabled = value; }
        }

        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定退出按钮的有效性")]
        public bool ExitButtonEnabled
        {
            get { return this.cmdExit.Enabled; }
            set { this.cmdExit.Enabled = value; }
        }


        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定导入按钮的有效性")]
        public bool ImportButtonEnabled
        {
            get { return this.cmdImport.Enabled; }
            set { this.cmdImport.Enabled = value; }
        }


        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定导出excel按钮的有效性")]
        public bool ExcelButtonEnabled
        {
            get { return this.cmdExcel.Enabled; }
            set { this.cmdExcel.Enabled = value; }
        }


        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定打印按钮的有效性")]
        public bool PrintButtonEnabled
        {
            get { return this.cmdPrint.Enabled; }
            set { this.cmdPrint.Enabled = value; }
        }

        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定查找按钮的有效性")]
        public bool SearchButtonEnabled
        {
            get
            {
                return this.cmdSearch.Enabled;
            }
            set
            {
                if (this.cmdSearch.Enabled == value)
                    return;
                this.cmdSearch.Enabled = value;
            }
        }

        [Bindable(true), Category("工具栏按钮有效化设定"), Description("设定履历按钮的有效性")]
        public bool logButtonEnabled
        {
            get
            {
                return this.cmdLog.Enabled;
            }
            set
            {
                if (this.cmdLog.Enabled == value)
                    return;
                this.cmdLog.Enabled = value;
            }
        }

       //各按钮的属性状态
       //查找按钮
        private DevExpress.XtraBars.BarButtonItem _CmdSearch;
        public DevExpress.XtraBars.BarButtonItem CmdSearch
        {
            get { return this.cmdSearch; }
            set { this.cmdSearch = value; }
        }

        //导入按钮
        private DevExpress.XtraBars.BarButtonItem _CmdImport;
        public DevExpress.XtraBars.BarButtonItem CmdImport
        {
            get { return this.cmdImport; }
            set { this.cmdImport = value; }
        }


        //导出EXCEL按钮
        private DevExpress.XtraBars.BarButtonItem _CmdExcel;
        public DevExpress.XtraBars.BarButtonItem CmdExcel
        {
            get { return this.cmdExcel; }
            set { this.cmdExcel = value; }
        }

        //打印按钮
        private DevExpress.XtraBars.BarButtonItem _CmdPrint;
        public DevExpress.XtraBars.BarButtonItem CmdPrint
        {
            get { return this.cmdPrint; }
            set { this.cmdPrint = value; }
        }

        //退出按钮
        private DevExpress.XtraBars.BarButtonItem _CmdExit;
        public DevExpress.XtraBars.BarButtonItem CmdExit
        {
            get { return this.cmdExit; }
            set { this.cmdExit = value; }
        }

        //履历按钮
        private DevExpress.XtraBars.BarButtonItem _CmdLog;
        public DevExpress.XtraBars.BarButtonItem CmdLog
        {
            get { return this.cmdLog; }
            set { this.cmdLog = value; }
        }

        #endregion

        public frmBaseToolXC()
        {
            InitializeComponent();
           
            
        }

        private void ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            //if (e.Item.Tag!=null)
            //{
            //    if (e.Item.Tag.ToString()=="exit")
            //    {
            //        this.Dispose();
            //        return;
            //    }
            this.ToolButtonClick(this.barManager, e.Item.Tag.ToString());

            //}
        }


        void frmBaseToolXC_ToolButtonClick(object sender, string e)
        {

        }


        /// <summary>
        /// 设定工具栏的可视性
        /// </summary>
        /// <param name="toolvisible">是否是基础表，明细基础表，还是业务数据表，还是查询</param>
        public void SetToolVisible(common.ToolVisible toolvisible)
        {
            switch (toolvisible)
            {
                case common.ToolVisible.BasicEntry:
                    this.ImportButtonVisibility= false;
                    this.SearchButtonVisibility= false;
                    this.logButtonVisibility = false;
                    
                    break;
                case common.ToolVisible.BasicDetailEntry:
                    this.ImportButtonVisibility= false;
                    break;
                case common.ToolVisible.BasicDetailEntryC:
                    this.ImportButtonVisibility = false;
                   
                    break;
                case common.ToolVisible.MasterData:
                    break;
                case common.ToolVisible.ImportData:
                    this.NewButtonVisibility = false;
                    this.DeleteButtonVisibility = false;
                    this.EditButtonVisibility = false;
                    this.SaveButtonVisibility = false;
                    this.CancelButtonVisibility = false;
                    break;
                case common.ToolVisible.QueryData:
                    this.ImportButtonVisibility= false;
                    this.NewButtonVisibility = false;
                    this.DeleteButtonVisibility = false;
                    this.EditButtonVisibility = false;
                    this.SaveButtonVisibility = false;
                    this.CancelButtonVisibility = false;
                    this.logButtonVisibility = false;
                    break;
                case common.ToolVisible.Information:
                    this.ImportButtonVisibility = false;
                    this.SearchButtonVisibility = false;
                    this.PrintButtonVisibility = false;
                    this.NewButtonVisibility = false;
                    this.DeleteButtonVisibility = false;
                    this.EditButtonVisibility = false;
                    this.SaveButtonVisibility = false;
                    this.CancelButtonVisibility = false;
                    this.logButtonVisibility = false;
                    break;
                case common.ToolVisible.Business:
                    break;
            }
        }

        private void frmBaseToolXC_Load(object sender, EventArgs e)
        {
            //this.barInformation.Visible = false;
        }

        private void frmBaseToolXC_FormClosing(object sender, FormClosingEventArgs e)
        {
            //serial.SerializeBinary(common.sysParameter, Application.StartupPath + @"\NNLInterface.dat");
            //common.SaveToolBarLayout(this.Name, this.barmanager);

        }


        


    }
}
